[Main] - User encounters a "record is not open" error when attaching a document to a posted sales shipment in Dynamics 365 (Base Application v28). - #10160
Open
DhavalMore88 wants to merge 4 commits into
Open
Conversation
…rs-a-record-is-not-open-error-when-attaching
DhavalMore88
requested review from
neeleshsinghal
and removed request for
neeleshsinghal
August 14, 2026 12:49
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a runtime failure when uploading document attachments from the Documents FactBox on posted Sales Shipments and Return Receipts by ensuring the underlying RecordRef is opened/resolved for those source tables, and by surfacing a clearer error when the source record cannot be resolved.
Changes:
- Extend
Document Attachment Mgmt.GetRefTable with missing mappings for Sales Shipment Header and Return Receipt Header. - Harden
Doc. Attachment List Factboxactions (upload/show details/attach from email) to error explicitly when the sourceRecordRefremains unresolved after the failure event hook. - Add automated tests (W1 + ES layers) validating attachment upload succeeds for posted sales shipments and posted return receipts.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Layers/W1/Tests/Misc/DocumentAttachmentTests.Codeunit.al | Adds coverage for uploading attachments on posted sales shipments/return receipts; includes helper setup for posting prerequisites. |
| src/Layers/W1/BaseApp/Foundation/Attachment/DocumentAttachmentMgmt.Codeunit.al | Adds GetRefTable branches to open/resolve RecordRef for Sales Shipment Header and Return Receipt Header. |
| src/Layers/W1/BaseApp/Foundation/Attachment/DocAttachmentListFactbox.Page.al | Prevents passing an unopened RecordRef to attachment save flows; raises a clearer “unsupported table” error if still unresolved. |
| src/Layers/ES/Tests/Misc/DocumentAttachmentTests.Codeunit.al | Mirrors the W1 test additions for the ES test layer. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug 646549: [master] [All-E] [SME][SaaS] User encounters a "record is not open" error when attaching a document to a posted sales shipment in Dynamics 365 (Base Application v28).
AB#646549
Issue: When a user uploads a file from the Documents FactBox ("Doc. Attachment List Factbox", Page 1178) on a Posted Sales Shipment, the upload fails with the runtime error "The record is not open." The same happens on Posted Return Receipt, while the identical action works correctly on Sales Order, Purchase Order and Posted Sales Invoice. The AL call stack points to Table 1173 "Document Attachment".InsertAttachment / SaveAttachmentFromStream.
Cause: The GetRefTable procedure in DocumentAttachmentMgmt.Codeunit.al (Codeunit 1173) has a case DocumentAttachment."Table ID" statement with no branch for Database::"Sales Shipment Header" (110) or Database::"Return Receipt Header" (6661), even though both tables are already registered in TableHasNumberFieldPrimayKey. Because no branch matches, RecRef.Open() is never called, GetRefTable returns false, and the FactBox's AttachmentsUpload action ignored that result and passed the unopened RecordRef on to DocumentAttachment.SaveAttachment(files, RecRef), where RecRef.Find() in InsertAttachment throws "The record is not open."
Solution: Added the missing Database::"Sales Shipment Header" and Database::"Return Receipt Header" cases to GetRefTable, each opening the RecordRef on its table and calling GetTable when the posted document is found — matching the existing pattern used for Sales Invoice Header and Sales Cr.Memo Header. Additionally hardened all three GetRefTable call sites in DocAttachmentListFactbox.Page.al (Upload files, Show details, Attach from email) to raise a clear error when the source record still cannot be resolved after the OnAfterGetRecRefFail event, instead of letting an unopened RecordRef reach the platform and surface the cryptic message for any other unmapped table.